//
//  ProductNextStepViewController.m
//  1gene
//
//  Created by 1jiyin on 16/5/6.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "ProductNextStepViewController.h"
#import "Order.h"
#import "DataSigner.h"
#import <AlipaySDK/AlipaySDK.h>
#import "ChangeGoodsAddressViewController.h"
#import "APAuthV2Info.h"
#import "AddressModel.h"
@implementation Product


@end

@interface ProductNextStepViewController ()<UITextFieldDelegate,UIScrollViewDelegate>




@property(nonatomic,copy)UIScrollView *myScrollView;

@property(nonatomic,assign)NSInteger scrollViewIndex;

@property(nonatomic,copy)NSMutableArray *messageDataArray;

@property(nonatomic,assign)CGRect myFrame;

@property(nonatomic,copy)UILabel *l1;

@property(nonatomic,copy)UILabel *l2;

@property(nonatomic,copy)UILabel *l3;

@property(nonatomic,copy)UILabel *l6;

@property(nonatomic,assign)NSInteger currentIndex;

@property(nonatomic,copy)NSMutableArray *dataArray;

@property(nonatomic,copy)UITextField *messageTextField;

@property(nonatomic,copy)NSString *addressId;

@property(nonatomic,copy)NSDictionary *tradeDic;

@property(nonatomic,copy)NSString *tradeNum;

@property(nonatomic,copy)UITextField *leaveMessageTextField;


@end

@implementation ProductNextStepViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:[UIView new]];
    [self createNavigation];
    [self initData];
    [self createUI];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardIsShow:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardIsHidden:) name:UIKeyboardDidHideNotification object:nil];
    
    
    
    NSLog(@"总价格========%f",_allMoney);
    // Do any additional setup after loading the view.
}
static int state=0;
-(void)keyBoardIsShow:(NSNotification *)notify
{
    NSDictionary *dic=notify.userInfo;
    NSLog(@"===============%@",dic);
    CGRect frame=[[dic objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

    if (state==0) {
        _myScrollView.contentSize=CGSizeMake(_myScrollView.frame.size.width, _myScrollView.contentSize.height+frame.size.height);
        state=1;
    }
    
}

-(void)keyBoardIsHidden:(NSNotification *)notify
{
    NSDictionary *dic=notify.userInfo;
    NSLog(@"===============%@",dic);
    CGRect frame=[[dic objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
   
    if (state==1) {
         _myScrollView.contentSize=CGSizeMake(_myScrollView.frame.size.width, _myScrollView.contentSize.height-frame.size.height);
        state=0;
    }
}


-(void)initData
{
    //_arr1=@[@"高血压",@"高血脂",@"老年痴呆",@"心脏病",@"类风湿",@"关节炎",@"老年病",@"近视"];
    
    //_arr2=@[@"抽烟",@"喝酒",@"油腻食物"];
    
    _dataArray=[NSMutableArray array];
    
    _messageDataArray=[NSMutableArray array];
    _currentIndex=0;
    for (int i=0; i<_productNumber; i++) {
        NSArray *ill=[NSArray array];
        NSArray *life=[NSArray array];
        NSString *name=nil;
        NSMutableDictionary *dic=[NSMutableDictionary dictionary];
        [dic setValue:ill forKey:@"ill"];
        [dic setValue:life forKey:@"life"];
        [dic setValue:name forKey:@"name"];
        [_dataArray addObject:dic];
    }
}

-(void)createUI
{
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-50-64)];
    scrollView.showsVerticalScrollIndicator=NO;
    scrollView.showsHorizontalScrollIndicator=NO;
    [self.view addSubview:scrollView];
    scrollView.contentSize=CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height*1.5);
    
        
        UILabel *l1=[[UILabel alloc]initWithFrame:CGRectMake(15, 10, (self.view.frame.size.width-70)/2.0, 30)];
        l1.text=@"收货人:";
        l1.textColor=[UIColor blackColor];
        l1.font=[UIFont systemFontOfSize:14];
        [scrollView addSubview:l1];
         _l1=l1;
        
        
        UILabel *l2=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(l1.frame), 10, (self.view.frame.size.width-70)/2.0, 30)];
        l2.text=@"手机号:";
        l2.textColor=[UIColor blackColor];
        l2.font=[UIFont systemFontOfSize:14];
        [scrollView addSubview:l2];
         _l2=l2;
        
        
        UILabel *l3=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(l1.frame), self.view.frame.size.width-15-55, 30)];
        l3.text=@"收货地址:";
        l3.textColor=[UIColor blackColor];
        l3.font=[UIFont systemFontOfSize:14];
        l3.numberOfLines=0;
        if ([l3 boundingRectWithSize:CGSizeMake(l3.frame.size.width, 0)].height>30) {
            l3.frame=CGRectMake(15, CGRectGetMaxY(l1.frame), self.view.frame.size.width-15-55, 50);
        }
        [scrollView addSubview:l3];
         _l3=l3;
        
        
        UIButton *changeMessageBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        changeMessageBtn.frame=CGRectMake(self.view.frame.size.width-15-25, (60-25)/2.0+10, 25, 25);
        [changeMessageBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
        [changeMessageBtn addTarget:self action:@selector(changeMessageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:changeMessageBtn];
        
        UIView *line1=[[UIView alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 15)];
        line1.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [scrollView addSubview:line1];
        
        //留言
        UILabel *l4=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(line1.frame), 80, 30)];
        l4.text=@"请留言";
        l4.font=[UIFont systemFontOfSize:16];
        l4.textColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
        [scrollView addSubview:l4];
        
        UIView *line2=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l4.frame), self.view.frame.size.width, 0.5)];
        line2.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [scrollView addSubview:line2];
        
        UIView *v1=[[UIView alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(line2.frame)+15, self.view.frame.size.width-20*2, 40)];
        v1.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        v1.layer.borderColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1].CGColor;
        v1.layer.borderWidth=4.0;
        v1.layer.cornerRadius=10.0;
        [scrollView addSubview:v1];
        
        UITextField *f1=[[UITextField alloc]initWithFrame:CGRectMake(5, 5, v1.frame.size.width-5*2, v1.frame.size.height-5*2)];
        f1.backgroundColor=[UIColor whiteColor];
        f1.layer.borderColor=[UIColor grayColor].CGColor;
        f1.layer.borderWidth=1.0;
        f1.layer.cornerRadius=5.0;
        f1.clearButtonMode=UITextFieldViewModeWhileEditing;
        f1.textColor=[UIColor blackColor];
        f1.font=[UIFont systemFontOfSize:14];
        f1.returnKeyType=UIReturnKeyDone;
        f1.delegate=self;
        f1.tag=10000;
        [v1 addSubview:f1];
        _leaveMessageTextField=f1;
    
        
        UIView *line3=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(v1.frame)+15, self.view.frame.size.width, 15)];
        line3.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [scrollView addSubview:line3];
        
        //联系方式
        UILabel *l5=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(line3.frame), 80, 30)];
        l5.text=@"联系方式";
        l5.font=[UIFont systemFontOfSize:16];
        l5.textColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
        [scrollView addSubview:l5];
        
        UIView *line4=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l5.frame), self.view.frame.size.width, 1)];
        line4.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [scrollView addSubview:line4];
        
        UILabel *l6=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(line4.frame), self.view.frame.size.width, 60)];
        l6.text=@"手机号码:";
        l6.font=[UIFont systemFontOfSize:14];
        l6.textColor=[UIColor blackColor];
        [scrollView addSubview:l6];
        _l6=l6;
        
        UIView *line5=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l6.frame), self.view.frame.size.width, 15)];
        line5.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [scrollView addSubview:line5];
    
    
    UIView *subCustomView=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(line5.frame), self.view.frame.size.width, scrollView.frame.size.height-CGRectGetMaxY(line5.frame))];
    [scrollView addSubview:subCustomView];
    
    UIScrollView *subScrollView=[[UIScrollView alloc]initWithFrame:subCustomView.bounds];
    subScrollView.showsVerticalScrollIndicator=NO;
    subScrollView.showsHorizontalScrollIndicator=NO;
    subScrollView.pagingEnabled=YES;
    subScrollView.bounces=NO;
    subScrollView.contentSize=CGSizeMake(self.view.frame.size.width*_productNumber, subScrollView.frame.size.height);
    subScrollView.delegate=self;
    [subCustomView addSubview:subScrollView];
    
    
    for (int m=0; m<_productNumber; m++) {
        
        
        UIView *subView11=[[UIView alloc]initWithFrame:CGRectMake(subScrollView.frame.size.width*m, 0, subScrollView.frame.size.width, subScrollView.frame.size.height)];
        [subScrollView addSubview:subView11];
        
        
        
        //疾病史
        CGFloat width=(self.view.frame.size.width-15*2-10*3)/4.0;
        CGFloat l_w=width-15-5;
        CGFloat l_h=15;
        
        UILabel *l7=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 30)];
        l7.text=@"疾病史";
        l7.font=[UIFont systemFontOfSize:16];
        l7.textColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
        [subView11 addSubview:l7];
        
        
        //提示箭头
        if (m==0&&_productNumber>1) {
            UIImageView *attentionImageView=[[UIImageView alloc]initWithFrame:CGRectMake(subView11.frame.size.width-30-15, (30-15)/2.0, 28, 15)];
            attentionImageView.image=[UIImage imageNamed:@"twoDirection"];
            [subView11 addSubview:attentionImageView];
        }

        
        
        UIView *line6=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l7.frame), self.view.frame.size.width, 1)];
        line6.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [subView11 addSubview:line6];
        
        for (int i=0; i<[self getHang:_arr1]; i++) {
            for (int j=0; j<4; j++) {
                if (i*4+j<_arr1.count) {
                    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                    btn.frame=CGRectMake(15+(width+10)*j, CGRectGetMaxY(line6.frame)+15+(l_h+15)*i, 15, 15);
                    [btn setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzekuang"] forState:UIControlStateNormal];
                    btn.tag=i*4+j+100*m;
                    [btn addTarget:self action:@selector(selectedIllness:) forControlEvents:UIControlEventTouchUpInside];
                    [subView11 addSubview:btn];
                    
                    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(btn.frame)+5, btn.frame.origin.y, l_w, l_h)];
                    lab.text=_arr1[i*4+j];
                    lab.font=[UIFont systemFontOfSize:14];
                    lab.textColor=[UIColor blackColor];
                    [subView11 addSubview:lab];
                    
                }
            }
            
        }
        
        
        
        
        
        UIView *line7=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(line6.frame)+15+(15+15)*[self getHang:_arr1]+5, self.view.frame.size.width, 15)];
        line7.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [subView11 addSubview:line7];
        
        //生活习惯
        UILabel *l8=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(line7.frame), 80, 30)];
        l8.text=@"生活习惯";
        l8.font=[UIFont systemFontOfSize:16];
        l8.textColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
        [subView11 addSubview:l8];
        
        UIView *line8=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l8.frame), self.view.frame.size.width, 1)];
        line8.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [subView11 addSubview:line8];
        
        
        for (int i=0; i<[self getHang:_arr2]; i++) {
            for (int j=0; j<4; j++) {
                if (i*4+j<_arr2.count) {
                    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
                    btn.frame=CGRectMake(15+(width+10)*j, CGRectGetMaxY(line8.frame)+15+(l_h+15)*i, 15, 15);
                    [btn setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzekuang"] forState:UIControlStateNormal];
                    btn.tag=i*4+j+1000*m;
                    [btn addTarget:self action:@selector(selectedLife:) forControlEvents:UIControlEventTouchUpInside];
                    [subView11 addSubview:btn];
                    
                    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(btn.frame)+5, btn.frame.origin.y, l_w, l_h)];
                    lab.text=_arr2[i*4+j];
                    lab.font=[UIFont systemFontOfSize:14];
                    lab.textColor=[UIColor blackColor];
                    [subView11 addSubview:lab];
                    
                }
            }
            
        }
        
        
        
        UIView *line9=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l8.frame)+15+(l_h+15)*[self getHang:_arr2], self.view.frame.size.width, 15)];
        line9.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [subView11 addSubview:line9];
        
        //采样人
        UILabel *l9=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(line9.frame), 80, 30)];
        l9.text=[NSString stringWithFormat:@"采样人%d",m+1];
        l9.font=[UIFont systemFontOfSize:16];
        l9.textColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
        [subView11 addSubview:l9];
        
        UIView *line10=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(l9.frame), self.view.frame.size.width, 0.5)];
        line10.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        [subView11 addSubview:line10];
        
        UIView *v9=[[UIView alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(line10.frame)+15, self.view.frame.size.width-20*2, 40)];
        v9.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
        v9.layer.borderColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1].CGColor;
        v9.layer.borderWidth=4.0;
        v9.layer.cornerRadius=10.0;
        [subView11 addSubview:v9];
        
        UITextField *f9=[[UITextField alloc]initWithFrame:CGRectMake(5, 5, v9.frame.size.width-5*2, v9.frame.size.height-5*2)];
        f9.placeholder=@" 采样人姓名";
        f9.backgroundColor=[UIColor whiteColor];
        f9.layer.borderColor=[UIColor grayColor].CGColor;
        f9.layer.borderWidth=1.0;
        f9.layer.cornerRadius=5.0;
        f9.clearButtonMode=UITextFieldViewModeWhileEditing;
        f9.textColor=[UIColor blackColor];
        f9.font=[UIFont systemFontOfSize:14];
        f9.returnKeyType=UIReturnKeyDone;
        f9.delegate=self;
        f9.tag=10001+m;
        [v9 addSubview:f9];
        
        subView11.frame=CGRectMake(subView11.frame.origin.x, subView11.frame.origin.y, subView11.frame.size.width, CGRectGetMaxY(v9.frame));
        subCustomView.frame=CGRectMake(0, subCustomView.frame.origin.y, subCustomView.frame.size.width, CGRectGetMaxY(v9.frame));
        subScrollView.frame=subCustomView.bounds;
         scrollView.contentSize=CGSizeMake(self.view.frame.size.width, scrollView.frame.size.height*1.5);

    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    _myScrollView=scrollView;
    
    // 添加手势，用户取消textField相应时间
    UITapGestureRecognizer *myScrollViewTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelEdit:)];
    [_myScrollView addGestureRecognizer:myScrollViewTapGes];
    
    //总金额
    UILabel *allLab=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(scrollView.frame), self.view.frame.size.width/2.0, 50)];
    allLab.text=[NSString stringWithFormat:@"合计: ¥%.1f",_allMoney];
    allLab.textColor=[UIColor blackColor];
    allLab.font=[UIFont systemFontOfSize:14];
    allLab.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:allLab];

    //购买
    UIButton *buyBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    buyBtn.frame=CGRectMake(self.view.frame.size.width/2.0, CGRectGetMaxY(scrollView.frame), self.view.frame.size.width/2.0, 50);
    [buyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
    buyBtn.backgroundColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
    buyBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [buyBtn addTarget:self action:@selector(buyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buyBtn];
    

    
    
}



//修改基本信息
-(void)changeMessageBtnClick:(UIButton *)sender
{
    ChangeGoodsAddressViewController *vc=[[ChangeGoodsAddressViewController alloc]init];
    vc.returnAddressModel=^(AddressModel *model){
        _l1.text=[NSString stringWithFormat:@"收货人:%@",model.receiver];
        _l2.text=[NSString stringWithFormat:@"手机号:%@",model.phone];
        _l3.text=[NSString stringWithFormat:@"收货地址:%@%@%@",model.province,model.city,model.detail];
        _l6.text=[NSString stringWithFormat:@"手机号:%@",model.phone];
        _addressId=[NSString stringWithFormat:@"%@",model.addressId];
        
        NSDictionary *dic=@{@"name":model.receiver,@"address":model.addressId,@"telephone":model.phone};
        [_messageDataArray addObject:dic];
        
    };
    [self.navigationController pushViewController:vc animated:YES];
}

//选择疾病
-(void)selectedIllness:(UIButton *)sender
{
    [self makeDataArray:sender AndName:@"ill" AndArray:_arr1 AndMyIndex:100];
//    NSMutableDictionary *dic=_dataArray[_currentIndex];
//    NSMutableArray *arr=[NSMutableArray arrayWithArray:dic[@"ill"]];
//    BOOL selected=YES;
//    NSInteger index=0;
//    for (NSInteger i=0; i<arr.count; i++) {
//        if (i==sender.tag-100*_currentIndex) {
//            selected=NO;
//            index=i;
//            break;
//        }
//    }
//    if (selected) {
//        //选中
//        NSMutableArray *arr1=[NSMutableArray arrayWithArray:arr];
//        [arr1 addObject:_arr1[sender.tag-100*_currentIndex]];
//        NSArray *arr2=[NSArray arrayWithArray:arr1];
//        [dic setValue:arr2 forKey:@"ill"];
//        [_dataArray replaceObjectAtIndex:_currentIndex withObject:dic];
//        [sender setBackgroundImage:[UIImage imageNamed:@"iconfont-fuxuankuang-3"] forState:UIControlStateNormal];
//        
//    }else{
//        //取消
//        NSMutableArray *arr1=[NSMutableArray arrayWithArray:arr];
//        [arr1 removeObjectAtIndex:index];
//        NSArray *arr2=[NSArray arrayWithArray:arr1];
//        [dic setValue:arr2 forKey:@"ill"];
//        [_dataArray replaceObjectAtIndex:_currentIndex withObject:dic];
//        [sender setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzekuang"] forState:UIControlStateNormal];
//    }
}
-(void)makeDataArray:(UIButton *)sender AndName:(NSString *)name AndArray:(NSArray *)myArr AndMyIndex:(NSInteger)myIndex
{
    NSMutableDictionary *dic=_dataArray[_currentIndex];
    NSMutableArray *arr=[NSMutableArray arrayWithArray:dic[name]];
    BOOL selected=YES;
    NSInteger index=0;
    for (NSInteger i=0; i<arr.count; i++) {
        if (i==sender.tag-myIndex*_currentIndex) {
            selected=NO;
            index=i;
            break;
        }
    }
    if (selected) {
        //选中
        NSMutableArray *arr1=[NSMutableArray arrayWithArray:arr];
        [arr1 addObject:myArr[sender.tag-myIndex*_currentIndex]];
        NSArray *arr2=[NSArray arrayWithArray:arr1];
        [dic setValue:arr2 forKey:name];
        [_dataArray replaceObjectAtIndex:_currentIndex withObject:dic];
        [sender setBackgroundImage:[UIImage imageNamed:@"iconfont-fuxuankuang-3"] forState:UIControlStateNormal];
        
    }else{
        //取消
        NSMutableArray *arr1=[NSMutableArray arrayWithArray:arr];
        [arr1 removeObjectAtIndex:index];
        NSArray *arr2=[NSArray arrayWithArray:arr1];
        [dic setValue:arr2 forKey:name];
        [_dataArray replaceObjectAtIndex:_currentIndex withObject:dic];
        [sender setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzekuang"] forState:UIControlStateNormal];
    }

}
//选择生活习惯
-(void)selectedLife:(UIButton *)sender
{
    [self makeDataArray:sender AndName:@"life" AndArray:_arr2 AndMyIndex:1000];
}

//scrollView的代理
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    _currentIndex=(int)scrollView.contentOffset.x/scrollView.frame.size.width;
}

//textField的代理

//- (void)textFieldDidBeginEditing:(UITextField *)textField
//{
//    if (textField.tag == 10000) {
//        
//    } else {
//        
//        // 改变myScrollView的transform
//        [UIView animateWithDuration:1 animations:^{
//            _myScrollView.transform = CGAffineTransformTranslate(_myScrollView.transform, 0, -300 * kAdjustParamater);
//        } completion:^(BOOL finished) {
//            
//        }];
//    }
//}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.tag==10000) {
        // 说明是请留言
    }else{
        if (textField.text.length==0) {
            [self.view showTiShiMessage:@"采样人不能为空"];
            
            NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithDictionary:_dataArray[_currentIndex]];
            [dic setObject:textField.text forKey:@"name"];
            [_dataArray replaceObjectAtIndex:_currentIndex withObject:dic];
            
            return;
        }else{
            NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithDictionary:_dataArray[_currentIndex]];
            [dic setObject:textField.text forKey:@"name"];
            [_dataArray replaceObjectAtIndex:_currentIndex withObject:dic];
        }
     
    }
}



//购买
-(void)buyBtnClick:(UIButton *)sender
{
    NSString *simple_info_name=@"";
    NSString *simple_info_disease_history=@"";;
    NSString *simple_info_live_prefer=@"";
    
    
    NSLog(@"购买的选择参数======%@",_dataArray);

    if (_dataArray.count==0) {
        simple_info_name=@"%%";
        simple_info_disease_history=@"%%";
        simple_info_live_prefer=@"%%";
    }
   else if (_dataArray.count==1) {
        simple_info_name=[NSString stringWithFormat:@"%@++",_dataArray[0][@"name"]];
       
       //疾病史
       NSMutableArray *arr1=[NSMutableArray array];
       for (int i=0; i<_illOriginalArray.count; i++) {
           for (int j=0; j<[_dataArray[0][@"ill"] count]; j++) {
               NSLog(@"hhhh=====%@====%@",_dataArray[0][@"ill"][j],_illOriginalArray[i][@"name"]);
               if ([_illOriginalArray[i][@"name"] isEqualToString:_dataArray[0][@"ill"][j]]) {
                   NSLog(@"======%d名称=====%@",i,_illOriginalArray[i][@"name"]);
                   [arr1 addObject:[NSString stringWithFormat:@"%@",_illOriginalArray[i][@"id"]]];
               }
           }

       }
       for (int i=0; i<[arr1 count]; i++) {
           if (simple_info_disease_history==nil) {
               simple_info_disease_history=[NSString stringWithFormat:@"%@,",arr1[i]];
           }else{
               simple_info_disease_history=[NSString stringWithFormat:@"%@%@,",simple_info_disease_history,arr1[i]];
           }
       }
       NSMutableString *str=[NSMutableString stringWithString:simple_info_disease_history];
       if ([str isEqualToString:@""]) {
           
       }else{
           [str deleteCharactersInRange:NSMakeRange(str.length-1, 1)];
       }
       
       simple_info_disease_history=[NSString stringWithFormat:@"%@--",str];
       simple_info_disease_history=[simple_info_disease_history stringByReplacingOccurrencesOfString:@"-" withString:@"%"];
       
       //生活习惯
       NSMutableArray *arr2=[NSMutableArray array];
       for (int i=0; i<_lifeOriginalArray.count; i++) {
           for (int j=0; j<[_dataArray[0][@"life"] count]; j++) {
               NSLog(@"hhhh=====%@====%@",_dataArray[0][@"life"][j],_lifeOriginalArray[i][@"name"]);
               if ([_lifeOriginalArray[i][@"name"] isEqualToString:_dataArray[0][@"life"][j]]) {
                   NSLog(@"======%d名称=====%@",i,_lifeOriginalArray[i][@"name"]);
                   [arr2 addObject:[NSString stringWithFormat:@"%@",_lifeOriginalArray[i][@"id"]]];
               }
           }
           
       }

       for (int i=0; i<[arr2 count]; i++) {
           if (simple_info_live_prefer==nil) {
               simple_info_live_prefer=[NSString stringWithFormat:@"%@,",arr2[i]];
           }else{
               simple_info_live_prefer=[NSString stringWithFormat:@"%@%@,",simple_info_live_prefer,arr2[i]];
           }
       }
       NSMutableString *str2=[NSMutableString stringWithString:simple_info_live_prefer];
       if ([str2 isEqualToString:@""]) {
           
       }else{
           [str2 deleteCharactersInRange:NSMakeRange(str2.length-1, 1)];
       }
       simple_info_live_prefer=[NSString stringWithFormat:@"%@--",str2];
       simple_info_live_prefer=[simple_info_live_prefer stringByReplacingOccurrencesOfString:@"-" withString:@"%"];

       
       
       
    }
    else if (_dataArray.count==2) {
        
        simple_info_name=[NSString stringWithFormat:@"%@+%@+",_dataArray[0][@"name"],_dataArray[1][@"name"]];
        
        
        //疾病史
        for (int i=0; i<2; i++) {
            //疾病史
            NSMutableArray *arr1=[NSMutableArray array];
            for (int m=0; m<_illOriginalArray.count; m++) {
                for (int n=0; n<[_dataArray[i][@"ill"] count]; n++) {
                    //NSLog(@"hhhh=====%@====%@",_dataArray[0][@"ill"][j],_arr1[i]);
                    if ([_illOriginalArray[m][@"name"] isEqualToString:_dataArray[i][@"ill"][n]]) {
                        NSLog(@"======%d名称=====%@",m,_illOriginalArray[m][@"name"]);
                        [arr1 addObject:[NSString stringWithFormat:@"%@",_illOriginalArray[m][@"id"]]];
                    }
                }
                
            }
            for (int m=0;m<[arr1 count]; m++) {
                if (simple_info_disease_history==nil) {
                    simple_info_disease_history=[NSString stringWithFormat:@"%@,",arr1[m]];
                }else{
                    simple_info_disease_history=[NSString stringWithFormat:@"%@%@,",simple_info_disease_history,arr1[m]];
                }
            }
            NSMutableString *str=[NSMutableString stringWithString:simple_info_disease_history];
            if ([str isEqualToString:@""]) {
                
            }else{
                [str deleteCharactersInRange:NSMakeRange(str.length-1, 1)];
            }
           [str insertString:@"%" atIndex:str.length];
            simple_info_disease_history=[NSString stringWithFormat:@"%@",str];
            
            
            
            
            //生活习惯
            
            
            
            NSMutableArray *arr2=[NSMutableArray array];
            for (int m=0; m<_lifeOriginalArray.count; m++) {
                for (int n=0; n<[_dataArray[i][@"life"] count]; n++) {
                    //NSLog(@"hhhh=====%@====%@",_dataArray[0][@"ill"][j],_arr1[i]);
                    if ([_arr2[m] isEqualToString:_dataArray[i][@"life"][n]]) {
                        NSLog(@"======%d名称=====%@",m,_lifeOriginalArray[m][@"name"]);
                        [arr2 addObject:[NSString stringWithFormat:@"%@",_lifeOriginalArray[m][@"id"]]];
                    }
                }
                
            }
            for (int m=0;m<[arr2 count]; m++) {
                if (simple_info_live_prefer==nil) {
                    simple_info_live_prefer=[NSString stringWithFormat:@"%@,",arr2[m]];
                }else{
                    simple_info_live_prefer=[NSString stringWithFormat:@"%@%@,",simple_info_live_prefer,arr2[m]];
                }
            }
            NSMutableString *str2=[NSMutableString stringWithString:simple_info_live_prefer];
            if ([str2 isEqualToString:@""]) {
                
            }else{
                [str2 deleteCharactersInRange:NSMakeRange(str2.length-1, 1)];
            }
            [str2 insertString:@"%" atIndex:str2.length];
            simple_info_live_prefer=[NSString stringWithFormat:@"%@",str2];
            
        }
        NSLog(@"第二个疾病史======%@",simple_info_disease_history);
    
    }else{
        for (int i=0; i<_dataArray.count; i++) {
            if (simple_info_name==nil) {
                simple_info_name=[NSString stringWithFormat:@"%@+",_dataArray[i][@"name"]];
            }else{
                simple_info_name=[NSString stringWithFormat:@"%@%@+",simple_info_name,_dataArray[i][@"name"]];
            }
            
        }
        NSMutableString *str3=[NSMutableString stringWithString:simple_info_name];
        if ([str3 isEqualToString:@""]) {
            
        }else{
            [str3 deleteCharactersInRange:NSMakeRange(str3.length-1, 1)];
        }
        simple_info_name=[NSString stringWithFormat:@"%@",str3];
        
        
        
        
        
        //疾病史
        for (int i=0; i<_dataArray.count; i++) {
            //疾病史
            NSMutableArray *arr1=[NSMutableArray array];
            for (int m=0; m<_illOriginalArray.count; m++) {
                for (int n=0; n<[_dataArray[i][@"ill"] count]; n++) {
                    //NSLog(@"hhhh=====%@====%@",_dataArray[0][@"ill"][j],_arr1[i]);
                    if ([_arr1[m] isEqualToString:_dataArray[i][@"ill"][n]]) {
                        NSLog(@"======%d名称=====%@",m,_illOriginalArray[m][@"name"]);
                        [arr1 addObject:[NSString stringWithFormat:@"%@",_illOriginalArray[m][@"id"]]];
                    }
                }
                
            }
            for (int m=0;m<[arr1 count]; m++) {
                if (simple_info_disease_history==nil) {
                    simple_info_disease_history=[NSString stringWithFormat:@"%@,",arr1[m]];
                }else{
                    simple_info_disease_history=[NSString stringWithFormat:@"%@%@,",simple_info_disease_history,arr1[m]];
                }
            }
            NSMutableString *str=[NSMutableString stringWithString:simple_info_disease_history];
            if ([str isEqualToString:@""]) {
                
            }else{
                [str deleteCharactersInRange:NSMakeRange(str.length-1, 1)];
            }
            [str insertString:@"%" atIndex:str.length];
            simple_info_disease_history=[NSString stringWithFormat:@"%@",str];
            
            
            
            
            //生活习惯
            
            
            
            NSMutableArray *arr2=[NSMutableArray array];
            for (int m=0; m<_lifeOriginalArray.count; m++) {
                for (int n=0; n<[_dataArray[i][@"life"] count]; n++) {
                    //NSLog(@"hhhh=====%@====%@",_dataArray[0][@"ill"][j],_arr1[i]);
                    if ([_arr2[m] isEqualToString:_dataArray[i][@"life"][n]]) {
                        NSLog(@"======%d名称=====%@",m,_lifeOriginalArray[m][@"name"]);
                        [arr2 addObject:[NSString stringWithFormat:@"%@",_lifeOriginalArray[m][@"id"]]];
                    }
                }
                
            }
            for (int m=0;m<[arr2 count]; m++) {
                if (simple_info_live_prefer==nil) {
                    simple_info_live_prefer=[NSString stringWithFormat:@"%@,",arr2[m]];
                }else{
                    simple_info_live_prefer=[NSString stringWithFormat:@"%@%@,",simple_info_live_prefer,arr2[m]];
                }
            }
            NSMutableString *str2=[NSMutableString stringWithString:simple_info_live_prefer];
            if ([str2 isEqualToString:@""]) {
                
            }else{
                [str2 deleteCharactersInRange:NSMakeRange(str2.length-1, 1)];
            }
            [str2 insertString:@"%" atIndex:str2.length];
            simple_info_live_prefer=[NSString stringWithFormat:@"%@",str2];
            
        }
        
        //疾病史
        NSMutableString *str1=[NSMutableString stringWithString:simple_info_disease_history];
        if ([str1 isEqualToString:@""]) {
            
        }else{
            [str1 deleteCharactersInRange:NSMakeRange(str1.length-1, 1)];
        }
        [str1 insertString:@"%" atIndex:str1.length];
        simple_info_live_prefer=[NSString stringWithFormat:@"%@",str1];
        
        //生活习惯
        NSMutableString *str2=[NSMutableString stringWithString:simple_info_live_prefer];
        if ([str2 isEqualToString:@""]) {
            
        }else{
            [str2 deleteCharactersInRange:NSMakeRange(str2.length-1, 1)];
        }
        [str2 insertString:@"%" atIndex:str2.length];
        simple_info_live_prefer=[NSString stringWithFormat:@"%@",str2];

        
        
        
        

    }
    
    
    
    simple_info_name=[simple_info_name stringByReplacingOccurrencesOfString:@"+" withString:@"%"];
    NSLog(@"得到的姓名=====%@疾病史=====%@生活习惯====%@",simple_info_name,simple_info_disease_history,simple_info_live_prefer);
    
    
    
    
    
    
    BOOL isReturn=NO;
   // NSLog(@"个人信息====%@",_messageDataArray);
    if (_messageDataArray.count==0) {
        isReturn=YES;
    }else{
        for (int i=0; i<_messageDataArray.count; i++) {
            if (_messageDataArray[i][@"name"]==nil) {
                isReturn=YES;
                break;
            }
            if (_messageDataArray[i][@"telephone"]==nil) {
                isReturn=YES;
                break;
            }
            if (_messageDataArray[i][@"address"]==nil) {
                isReturn=YES;
                break;
            }
        }
 
    }
    
    for (int i=0; i<_dataArray.count; i++) {
        if (_dataArray[i][@"name"]==nil) {
            [self.view showTiShiMessage:@"请填写采样人姓名"];
            return;
        }
    }
    
    
    if (isReturn) {
        [self.view showTiShiMessage:@"请选择收货地址"];
        return;
    }
    
    
//    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"此功能暂未开通" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
//    [alert show];
//    return;
    
    
    
  //  NSLog(@"购买的选择参数======%@",_dataArray);
    [self getTradeNumWithName:simple_info_name AndIll:simple_info_disease_history AndLife:simple_info_live_prefer];
    
}


-(void)startPayMoney
{
    NSString *partner = @"2088121657755650";
    NSString *seller = @"2818614395@qq.com";
    NSString *privateKey = @"MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAIOdoCVrr/bWnmPE aDYoPJSH7cfrtGBTMFQjeE2v73GlTEWPjJNs7T6aTPcmXNeIiyLmLzOL8AgArrn2 pjgpw04nIetW3ZaiczrRzK3E+zadfEDf4KighWgGeYVgLRfNYirDBnaqQMk3XcvD hYoF6hTZWg4q8ABNcvXTI4FLGWtVAgMBAAECgYBdbCp7xWee55KAMK7kGkV+DMo8 iVN8uC/q2U6QnlxxJ6rvCUj4cG4qbK5LFID8QKC6gfdpOGCF3a4otCoiXYqSTxEU untEqS5rtovxvW/fP3TPLZ3DFFIwt2F7np6dvRQ5sLqRvHWNS4r716XDXfxV/Bsf lEwaaxAOZ4/6uG1nVQJBAMC28NxyRb/9MdrEufKDjMcuZEnw1TjSJVyuKlS8eSdT vq12viH+ZWeFHYcq9U8ZVN0vKEWUBmCHV8qZlyKS2RMCQQCu1j8cMG0bkQuB8WHt Nvs80lRXqIMvfsyDco06JjAdUJfULs187qwSrMN2nhwWQf+8gFSPv7YFfqcfAYHR F173AkEAqVxcwq9eYwJl3OfErr8zahx4II8ZI61zDkc1hnB4XLp5OULAh2llvps6 vv5exVvyu8tkrfkPvadT3QYrz0OUpwJBAK2kSV+01Ng5EQXId6rCHXoFpxC8YzYL qBCw94SWItkqjvCEXz/CR5Hwldy8IUcV22kax2FRVPVWGaMYuxawMHcCQGir3STI 2uP/RIcShyA12ZfwzYRbJqtAVt3C991l8piDrf5n0lxtSP1TeFZ/L5zjDjCGEveN a5HJuj4re8xhyps=";
    /*============================================================================*/
    /*============================================================================*/
    /*============================================================================*/
    
    //partner和seller获取失败,提示
    if ([partner length]==0||[seller length]==0|| [privateKey length]==0) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"缺少partner或者seller或者私钥" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        return;
    }
    
    /*
     *生成订单信息及签名
     */
    //将商品信息赋予AlixPayOrder的成员变量
    Order *order=[[Order alloc]init];
    order.partner=partner;
    order.seller=seller;
    order.tradeNO=_tradeNum;//订单ID(由商家自行定制)
    order.productName=_model.name;//商品标题
    order.productDescription=_model.short_description_title;//商品描述
    order.amount=[NSString stringWithFormat:@"%.2f",_allMoney];//商品价格
    order.notifyURL=@"http://www.1gene.com";//回调URL
    
    
    order.service=  @"mobile.securitypay.pay";
    order.paymentType=@"1";
    order.inputCharset=@"utf-8";
    order.itBPay=@"30m";
    order.showUrl=@"m.alipay.com";
    
    //应用注册scheme,在AlixPayDemo-Info.plist定义URL types
    NSString *appScheme=@"1gene";
    
    //将商品信息拼接成字符串
    NSString *orderSpec=[order description];
    NSLog(@"orderSpec=======%@",orderSpec);
    
    
    //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
    id<DataSigner> singer=CreateRSADataSigner(privateKey);
    NSString *signedString=[singer signString:orderSpec];
    
    //将签名成功字符串格式化为订单字符串,请严格按照该格式
    NSString *orderString=nil;
    if (signedString != nil) {
        orderString=[NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",orderSpec,signedString,@"RSA"];
        [[AlipaySDK defaultService]payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
            NSLog(@"返回的result=======%@",resultDic);
            NSInteger resultState=[resultDic[@"resultStatus"] integerValue];
            if (resultState==9000) {
                [self havePaid];
            }
        }];
    }

}

//支付完成
-(void)havePaid
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *currentTime=[formatter stringFromDate:[NSDate date]];
    
    
    
    NSDictionary *params=@{@"order_id":_tradeDic[@"id"],@"total_fee":[NSString stringWithFormat:@"%2f",_allMoney],@"pay_time":currentTime};
    
    [manager POST:[NSString stringWithFormat:HavePaid,token] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"支付完成，数据提交==%@",dic);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error%@",error.localizedDescription);
    }];
}




#pragma mark 产生随机订单号
-(NSString *)generateTradeNO
{
    static int kNumber=15;
    NSString *sourceStr=@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    NSMutableString *resultStr=[[NSMutableString alloc]init];
    srand((unsigned)time(0));
    for (int i=0; i<kNumber; i++) {
        unsigned index=rand()%[sourceStr length];
        NSString *oneStr=[sourceStr substringWithRange:NSMakeRange(index, 1)];
        [resultStr appendString:oneStr];
    }
    return resultStr;
}

-(void)createNavigation
{
    self.navigationController.navigationBar.hidden=NO;
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
    //返回
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame=CGRectMake(0, 0, 25, 25);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"left_back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    
    //标题
    UILabel *title=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
    title.text=@"订单确认-2";
    title.font=[UIFont systemFontOfSize:22];
    title.textAlignment=NSTextAlignmentCenter;
    title.textColor=[UIColor whiteColor];
    self.navigationItem.titleView=title;
}

#pragma mark 返回上一页
-(void)leftBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)getHang:(NSArray *)arr
{
    NSInteger hang;
    if (arr.count%4==0) {
        hang=arr.count/4;
    }else{
        hang=arr.count/4+1;
    }
    return hang;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [self.navigationController.view endEditing:YES];
//    if (textField.tag == 10000) {
//        // 说明是留言
//    } else {
//        // 改变myScrollView的transform
//        [UIView animateWithDuration:1 animations:^{
//            _myScrollView.transform = CGAffineTransformTranslate(_myScrollView.transform, 0, 300 * kAdjustParamater);
//        } completion:^(BOOL finished) {
//            
//        }];
//    }
    return YES;
}


-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController.navigationBar setTranslucent:YES];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController.navigationBar setTranslucent:NO];
    state=0;
}

-(void)getTradeNumWithName:(NSString *)name AndIll:(NSString *)ill AndLife:(NSString *)life
{
    NSLog(@"获取订单号");
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    
        NSDictionary *params;
    if (_isUsedDiscount==0) {
        NSLog(@"111111");
       params= @{@"good_id":_model.shangPinID,@"quantity":[NSString stringWithFormat:@"%ld",_productNumber],@"address_id":_addressId,@"has_coupon":@"0",@"simple_info_name":name,@"simple_info_disease_history":ill,@"simple_info_live_prefer":life,@"leave_word":_leaveMessageTextField.text};
    }else{
         NSLog(@"2222222");
        params= @{@"good_id":_model.shangPinID,@"quantity":[NSString stringWithFormat:@"%ld",_productNumber],@"address_id":_addressId,@"has_coupon":@"1",@"coupon_receive_id":_discountId,@"simple_info_name":name,@"simple_info_disease_history":ill,@"simple_info_live_prefer":life,@"leave_word":_leaveMessageTextField.text};
    }
    NSLog(@"aaaaaaa=======%@",params);
    NSLog(@"得到的good_id=====%@=====_productNumber===%ld===addressId=====%@",_model.myID,_productNumber,_addressId);
    
    
    [self.view isLoading:YES];
    [manager POST:[NSString stringWithFormat:GetTradeNumber,[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.view isLoading:NO];
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"订单信息=====%@",dic);
        if (dic) {
            _tradeDic=[NSDictionary dictionaryWithDictionary:dic];
            _tradeNum=[NSString stringWithFormat:@"%@",dic[@"sn"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self startPayMoney];
            });
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.view isLoading:NO];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.view showTiShiMessage:@"交易失败"];
        });
        NSLog(@"订单错误error%@",error.localizedDescription);
    }];
}

#pragma mark - 取消界面编辑状态
- (void)cancelEdit:(UITapGestureRecognizer *)tapGes
{
    [_myScrollView endEditing:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
